﻿using M.Warehouse.API.Application.Command.InventoryCommand;
using M.Warehouse.Domain;
using M.Warehouse.Repository.WarehouseInterface;
using MediatR;

namespace M.Warehouse.API.Application.CommandHandlers.InventoryHandlers
{
    public class InventoryBackfillCommandHandlers : IRequestHandler<InventoryBackfillCommand, Inventory>
    {
        private readonly IInventoryRepository _inventoryRepository;
        public InventoryBackfillCommandHandlers(IInventoryRepository inventoryRepository)
        {
            _inventoryRepository = inventoryRepository;
        }
        /// <summary>
        /// 返填
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Inventory> Handle(InventoryBackfillCommand request, CancellationToken cancellationToken)
        {
            return (await _inventoryRepository.GetAllAsync()).Where(x => x.InventoryId == request.InventoryId).FirstOrDefault();
        }
    }
}
